package com.xhwl.logistics.strategy.impl;

import com.xhwl.logistics.bo.VehicleParkingLotSecondBO;
import com.xhwl.logistics.bo.cent.VehicleIntegratedConfigBO;
import com.xhwl.logistics.dto.http.FreeSpaceNumberKeTopDTO;
import com.xhwl.logistics.dto.http.query.QueryFreeSpaceNumberKeTopDTO;
import com.xhwl.logistics.service.impl.http.KeTopHttpServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;

import java.util.Date;

@Slf4j
//@Service
public class VehicleParkingLotKeTopStatisticsHandlerImpl extends VehicleParkingLotDefaultStatisticsHandlerImpl {

    @Autowired
    private KeTopHttpServiceImpl keTopHttpService;

    @Async("threadPoolTaskExecutorForSchedule")
    @Override
    public void statisticsCarportRecordToBi(VehicleIntegratedConfigBO vehicleIntegratedConfigBO) {
        Date processTime = new Date();
        Integer projectId = vehicleIntegratedConfigBO.getVehicleSystemInfoBO().getProjectId();

        log.info("statistics carport start!,project id: {}", projectId);

        VehicleParkingLotSecondBO vehicleParkingLotSecondBO = queryParkingLot(projectId);
        String parkingLotName = vehicleParkingLotSecondBO.getParkingLotName();

        FreeSpaceNumberKeTopDTO freeSpaceNumberKeTopDTO = keTopHttpService.queryFreeSpaceNumber(vehicleIntegratedConfigBO, new QueryFreeSpaceNumberKeTopDTO());
        Integer totalNumber = freeSpaceNumberKeTopDTO.getTotalNumber();
        Integer freeSpaceNumber = freeSpaceNumberKeTopDTO.getFreeSpaceNumber();
        int existingNumber = totalNumber - freeSpaceNumber;

        Date ingestionTime = new Date();

        biVehicleService.addDwsCarportRecordForHour(vehicleStatisticsConverter.toCreateBiVehicleCarportRecordMinuteFeignDTO(projectId, parkingLotName,
                totalNumber, freeSpaceNumber, existingNumber,
                processTime, ingestionTime));

        log.info("statistics carport end!,project id: {}", projectId);
    }

    @Async("threadPoolTaskExecutorForSchedule")
    @Override
    public void statisticsCardAccessRecordRecordToBi(VehicleIntegratedConfigBO vehicleIntegratedConfigBO) {
        super.statisticsCardAccessRecordRecordToBi(vehicleIntegratedConfigBO);
    }

    @Async("threadPoolTaskExecutorForSchedule")
    @Override
    public void statisticsLocationAccessRecordToBi(VehicleIntegratedConfigBO vehicleIntegratedConfigBO) {
        super.statisticsLocationAccessRecordToBi(vehicleIntegratedConfigBO);
    }

    @Async("threadPoolTaskExecutorForSchedule")
    @Override
    public void statisticsCardPayRecordToBi(VehicleIntegratedConfigBO vehicleIntegratedConfigBO) {
        super.statisticsCardPayRecordToBi(vehicleIntegratedConfigBO);
    }

}
